import 'dart:async';

import 'package:flutter/material.dart';
import 'package:luckiness/utils/general.dart';
import 'package:provider/single_child_widget.dart';

class Order extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return OrderState();
  }
}

class OrderState extends State<Order> with SingleTickerProviderStateMixin {

  Widget acquireCell(BuildContext context, int column) {
    double scale = widthScale(context);
    int tempIndex = column;
    Column lu = Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children:[
        Row(
          mainAxisAlignment:MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Padding(
              padding: EdgeInsets.symmetric(vertical:12 * scale),
              child: Text('外卖订单号:12334567899756', style:TextStyle(fontSize: 12 * scale, color:Color.fromRGBO(166, 166, 166, 1.0))),
            ),
            tempIndex == 2 ? 
              Text('已完成', style:TextStyle(fontSize:13 * scale, color:Color.fromRGBO(166, 166, 166, 1.0)))
              :
              Text('待付款', style:TextStyle(fontSize:13 * scale, color:Color.fromRGBO(136, 175, 213, 1.0))),
            
          ],    
        ),
        Divider(height:0, color:separatorLineColor),
        Padding(
          padding: EdgeInsets.only(top:12 * scale),
          child:Row(
            mainAxisAlignment:MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Expanded(
                child: Text(
                  '北京市朝阳区青年汇佳园10号', 
                  style:TextStyle(fontSize: 15 * scale, color:Color.fromRGBO(56, 56, 56, 1.0), fontWeight:FontWeight.bold,), 
                  overflow: TextOverflow.ellipsis,
                ),
              ),
              Text('2018-09-01 18:05', style:TextStyle(fontSize:12 * scale, color:Color.fromRGBO(166, 166, 166, 1.0))),
            ],    
          ),
        ),
        Padding(
          padding: EdgeInsets.symmetric(vertical:2.0 * scale),
          child:Text(
            '榛果拿铁 共2件商品',
            textAlign: TextAlign.start,
            style:TextStyle(fontSize:13, color:Color.fromRGBO(80, 80, 80, 1.0)),
          )
        ),
        Row(
          mainAxisAlignment:MainAxisAlignment.spaceBetween,
          children:[
            Padding(
              padding: EdgeInsets.fromLTRB(0, 25 * scale, 0, 18 * scale),
              child: Text(
                '￥20.0',
                style:TextStyle(color:Color.fromRGBO(56, 56, 56, 1.0), fontSize:14 * scale, fontWeight:FontWeight.bold),
              ),              
            ),
            GestureDetector(
              onTap:(){
                print('点击按钮');
                Navigator.of(context).pushNamed('payPage');
              },
              child:Container(
                width: 75 * scale,
                height: 30 * scale,
                decoration: BoxDecoration(
                  borderRadius:BorderRadius.circular(4),
                  border:Border.all(color:Color.fromRGBO(255, 129, 2, 1.0),),
                ),
                child: Center(
                  child: Text(
                    tempIndex == 2 ? '再来一单' : '去支付',
                    style:TextStyle(fontSize:13 * scale, color:Color.fromRGBO(255, 129, 2, 1.0)),
                  ),
                ),
              )
            )
          ],
        ) 
      ]
    );
    return Container(
      padding:EdgeInsets.fromLTRB(0, 0, 0, 10 * scale),
      color: Color.fromRGBO(234, 234, 234, 1.0),
      child: Container(
        padding: EdgeInsets.fromLTRB(15, 0, 15, 0 * scale),
        color:Colors.white,
        child:lu,
      ),
    );
  }

  Widget acqurieShowView(BuildContext context, int column) {
    return Center(
      child:ListView.builder(
        itemBuilder: (BuildContext context, int index){
          return acquireCell(context, column);
        },
        itemCount: 20,
      ),
    );
  }


  TabController tabCon;

  @override
  void initState() {
    tabCon = TabController(length: 3, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    tabCon.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        textTheme: TextTheme(
          title:TextStyle(fontSize: 18, fontWeight:FontWeight.bold, color:Colors.black87),
          button:TextStyle(fontSize: 15, fontWeight:FontWeight.normal, color:Colors.black87)
        ),
        title:Text('订单列表'),
        bottom:TabBar(tabs: [
          Tab(text: '全部',),
          Tab(text: '未完成',),
          Tab(text: '已完成',),
        ],
        unselectedLabelColor: Colors.black45,
        labelColor: Color.fromRGBO(136, 175, 213, 1.0),
        indicatorColor: Color.fromRGBO(136, 175, 213, 1.0),
        controller: tabCon,)
      ),
      body:TabBarView(
        controller: tabCon,
        children: [
          acqurieShowView(context, 0),
          acqurieShowView(context, 1),
          acqurieShowView(context, 2),
        ],)
    );
  }
}



/*
 CustomScrollView temp = CustomScrollView(
    physics: new BouncingScrollPhysics(),
    // 需要使用 slivers 才可以
    slivers: <Widget>[
        // 头部内容
        new SliverAppBar(
            // 高度
            expandedHeight: 456.0,
            pinned: true,
            floating: !true,
            snap: !true,
            flexibleSpace: new FlexibleSpaceBar(
                // 标题
                title: Text('标题'),
                centerTitle: true,
                // 背景图
                background: new Image.network(
                    'https://pics0.baidu.com/feed/060828381f30e924d499b8e45f68e5001c95f788.jpeg?token=94d7384ee7f74aafb2980984c6b11532',
                    fit: BoxFit.cover,
                ),
            ),
        ),
        // 列表内容
        new SliverList(
            delegate: new SliverChildBuilderDelegate((ctx, index) {
                return new Text('item: $index');
            }, childCount: 30),
        ),
    ],
);
*/